package com.biwin.module.orm.api.entity;

import com.biwin.common.api.constant.BwSystemConstant;
import com.biwin.common.api.entity.IBwEntity;
import com.biwin.common.api.vo.IBwVo;
import com.biwin.common.app.basic.BwObject;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * BiWin Framework Base Entity
 *
 * @author biwin
 * @since 0.0.1
 */
@MappedSuperclass
public abstract class BwBasicEntity extends BwObject implements IBwEntity, Serializable {

    private static final long serialVersionUID = 3011541661469398357L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    protected Long id;

    /**
     * is deleted
     * default false
     */
    @Column(name = BwSystemConstant.DELETED, columnDefinition = "BIT(1) NOT NULL DEFAULT B'0' COMMENT '是否删除'")
    protected Boolean deleted = false;

    /**
     * data creation date
     */
    @CreationTimestamp
    @Column(name = "create_time", columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP comment '记录创建时间'",
            updatable = false)
    protected Date createTime;

    /**
     * data updated date
     */
    @UpdateTimestamp
    @Column(name = "update_time", columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP comment '记录更新时间'",
            insertable = false)
    protected Date updateTime;

    /**
     * version number
     * Optimistic lock
     */
    @Version
    private Integer version;

    @Column(name = "operation_user", columnDefinition = "BIGINT(20) NOT NULL COMMENT '操作人人'")
    private Long operationUser;


    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public Boolean getDeleted() {
        return deleted;
    }

    @Override
    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    @Override
    public Date getCreateTime() {
        return createTime;
    }

    @Override
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public Date getUpdateTime() {
        return updateTime;
    }

    @Override
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public Integer getVersion() {
        return version;
    }

    @Override
    public void setVersion(Integer version) {
        this.version = version;
    }

    public Long getOperationUser() {
        return operationUser;
    }

    public void setOperationUser(Long operationUser) {
        this.operationUser = operationUser;
    }

    @Override
    public Map<String, Object> toMap() {
        return super.toMap();
    }

    @Override
    public String toJson() {
        return super.toJson();
    }

    //    @Override
    //    public <V extends IBwVo> V toVo(V v) {
    //        return null;
    //    }

    @Override
    public <V extends IBwVo, P extends IBwEntity> List<V> toVos(List<V> var1, List<P> var2) throws IllegalAccessException, InvocationTargetException {
        return null;
    }


}
